{extend name="layout/base" /}
<!-- 标题 -->
{block name="title"}用户分组{/block}
<!-- CSS -->
{block name="css"}{/block}
<!-- 具体内容 -->
{block name="content"}
<h2 class="header-dividing">用户分组 <small>User group</small></h2>
<div class="navbar navbar-default navbar-content">
    <div class="collapse navbar-collapse">
        <ul class="nav navbar-nav">
            {if(check_auth('group-create'))}<li><a class="manage-group-create" data-url="{:url('/manage/group_save')}"> <i class="icon icon-plus"></i> 添加分组</a></li>{/if}
            <li><a href="{:url('/manage')}"> <i class="icon icon-user"></i> 用户列表</a></li>
        </ul>
        <!-- 导航中的表单 -->
        <form class="navbar-form navbar-left" role="search" method="get" action="{:url('/manage/group')}">
            <input type="text" class="form-control" placeholder="搜索" name="keywords" value="{$keywords}">
            <button type="submit" class="btn btn-default">搜索</button>
        </form>
    </div>
</div>
<div class="panel">
    <table class="table datatable" data-checkable="true">
        <thead>
            <tr>
                <th data-width="50" width="50">ID</th>
                <th>用户组</th>
                <th data-width="120" width="120" class="text-center">分配权限</th>
                <th data-width="80" width="80" class="text-center">修改</th>
                <th data-width="80" width="80" class="text-center">删除</th>
            </tr>
        </thead>
        <tbody>
            {volist name="list" id="vo"}
            <tr data-id="{$vo['group_id']}">
                <td>{$vo['group_id']}</td>
                <td>
                    {$vo['group_name']}
                    {if($vo['group_action']=='')}
                        <label class="label label-danger">未分配权限</label>
                    {/if}
                </td>
                <td class="text-center">{if(check_auth('group-action'))}<a href="{:url('/manage/group_action', 'id='.$vo['group_id'])}" class="group-action">分配权限</a>{/if}</td>
                <td class="text-center">{if(check_auth('group-edit'))}<a class="manage-group-edit" data-url="{:url('/manage/group_update')}" data-id="{$vo['group_id']}" data-name="{$vo['group_name']}">修改</a>{/if}</td>
                <td class="text-center">{if(check_auth('group-delete'))}<a class="delete" data-url="{:url('/manage/group_delete','id='.$vo['group_id'])}">删除</a>{/if}</td>
            </tr>
            {/volist}
        </tbody>
    </table>
    <div class="mb10 ml10">
        {if(check_auth('group-delete'))}<button class="btn btn-danger check-delete" type="button" data-url="{:url('/manage/group_delete')}">删除选中</button>{/if}
    </div>
</div>
{/block}


<!-- JS -->
{block name="js"}{/block}

{block name="jscode"}
<script type="text/javascript">
$(document).ready(function() {
    // 添加分组
    $(".manage-group-create").click(function(event) {
        var $url = $(this).data('url');
        bootbox.prompt({
            title: "添加分组",
            callback: function(result) {
                if (result == null) {
                    return true;
                }
                if (result == '') {
                    return sxj.msg_error('请填写内容!');
                }
                sxj.ajax_post($url, { group_name: result });
            }
        });
    });

    // 修改分组
    $(".manage-group-edit").click(function(event) {
        var $id = $(this).data('id'),
            $name = $(this).data('name'),
            $url = $(this).data('url');
        bootbox.prompt({
            title: "修改分组",
            value: $name,
            callback: function(result) {
                if (result == null) {
                    return true;
                }
                if (result == '') {
                    return sxj.msg_error('请填写内容!');
                }
                sxj.ajax_post($url, { group_id: $id, group_name: result });
            }
        });
    });

    // 
    $(".group-action").click(function(event) {
        var iframe = $(this).attr('href');
        var options = {
            name: 'group-action',
            iframe: iframe,
            height: 500,
            title: '分配权限',
        };
        var myModalTrigger = new $.zui.ModalTrigger();
        myModalTrigger.show(options);options
        return false;
    });
});
</script>
{/block}